//
// Created by tanke on 23-11-28.
//

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int minTimeToType(char* word)
{
    int cnt = 0;
    char pos = 'a';

    for (size_t i = 0; i < strlen(word); i ++) {
        int dist_1 = 0;
        int dist_2 = 0;

        if (word[i] != pos) {

            if (word[i] > pos) {
                dist_1 = word[i] - pos;
            } else {
                dist_1 = 'z' - pos + 1 + word[i] - 'a';
            }

            if (word[i] < pos) {
                dist_2 = pos - word[i];
            } else {
                dist_2 = pos - 'a' + 1 + 'z' - word[i];
            }

            if (dist_1 > dist_2) {
                cnt += dist_2;
            } else {
                cnt += dist_1;
            }
        }
        cnt += 1;
        pos = word[i];
    }

    return cnt;
}

int main(void)
{
    const char* word = "abc";
    printf("%d\n", minTimeToType(word));

    return 0;
}
